/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.util.Iterator;
import javax.swing.JOptionPane;
import stamboom.*;

/**
 *
 * @author Cabez
 */
public class GezinFrame extends javax.swing.JFrame {

    /**
     * Creates new form GezinFrame
     */
    Administratie admin = null;

    public GezinFrame(Administratie a) {
        initComponents();
        admin = a;
        jtfVolgNr.setText("" + admin.getNextGezinsNr());

        for (Iterator<Persoon> it = admin.getAllepersonen(); it.hasNext();) {
            jcbOuder1.addItem(it.next().toString());
        }

        jcbOuder2.addItem("geen");
        for (Iterator<Persoon> it = admin.getAllepersonen(); it.hasNext();) {
            jcbOuder2.addItem(it.next().toString());
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jcbOuder1 = new javax.swing.JComboBox();
        jcbOuder2 = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jtfVolgNr = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jbtnVoegToe = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel1.setText("Gezin");

        jcbOuder1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbOuder1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Ouder 1");

        jLabel3.setText("Ouder 2");

        jtfVolgNr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfVolgNrActionPerformed(evt);
            }
        });

        jLabel4.setText("Volg nr");

        jbtnVoegToe.setText("Voeg toe");
        jbtnVoegToe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnVoegToeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jcbOuder1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jcbOuder2, 0, 287, Short.MAX_VALUE)
                            .addComponent(jtfVolgNr)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jbtnVoegToe, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jLabel1)
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfVolgNr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbOuder1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jcbOuder2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
                .addComponent(jbtnVoegToe)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtfVolgNrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfVolgNrActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtfVolgNrActionPerformed

    private void jcbOuder1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbOuder1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jcbOuder1ActionPerformed

    private void jbtnVoegToeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnVoegToeActionPerformed



        try {
            if (jcbOuder2.getSelectedItem().toString().equals("geen")) {
                admin.addGezin(admin.getPersoonDoorNaam(jcbOuder1.getSelectedItem().toString()), null);
            } else {
                admin.addGezin(admin.getPersoonDoorNaam(jcbOuder1.getSelectedItem().toString()), admin.getPersoonDoorNaam(jcbOuder2.getSelectedItem().toString()));
            }
            JOptionPane.showMessageDialog(this, "Gezin toegevoegd!");
            this.dispose();
        } catch (Exception ex) {

            JOptionPane.showMessageDialog(this, ex.getMessage());
            
        }
    }//GEN-LAST:event_jbtnVoegToeActionPerformed
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /*
//         * Set the Nimbus look and feel
//         */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /*
//         * If Nimbus (introduced in Java SE 6) is not available, stay with the
//         * default look and feel. For details see
//         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(GezinFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(GezinFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(GezinFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(GezinFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /*
//         * Create and display the form
//         */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new GezinFrame().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JButton jbtnVoegToe;
    private javax.swing.JComboBox jcbOuder1;
    private javax.swing.JComboBox jcbOuder2;
    private javax.swing.JTextField jtfVolgNr;
    // End of variables declaration//GEN-END:variables
}
